.av {
  user-select: none;
  box-sizing: border-box;
  display: flex;
  max-width: 100%;
  margin: 4px 0 !important;

  &:hover .av__views .block__icon {
    opacity: 1;
  }

  &__cursor {
    width: .1px;
    height: 0;
  }

  &__container {
    overflow-x: auto;
    overflow-y: hidden;
    cursor: auto;
  }

  &__pulse {
    width: 70%;
    height: 23px;
    display: block;
    position: relative;
    overflow: hidden;
    background: var(--b3-border-color);
    border-radius: var(--b3-border-radius);

    &:after {
      content: " ";
      border-radius: var(--b3-border-radius);
      position: absolute;
      z-index: 1;
      animation: 1s linear infinite keyframes-pulse;
      background: linear-gradient(90deg, transparent 0, rgba(255, 255, 255, .4) 50%, transparent 100%);
      display: block;
      height: 100%;
      width: 100%;
    }
  }

  &__header {
    top: -43px;
    z-index: 2;

    .layout-tab-bar {
      background-color: transparent;

      .item__graphic {
        height: calc(1.625em - 10px);
        width: calc(1.625em - 10px);
        padding: 10px 5px 10px 8px;
        line-height: calc(1.625em - 10px);
        font-size: inherit;
        text-align: center;
      }

      .item__text {
        padding-left: 5px;
        line-height: normal;
      }
    }
  }

  &__views {
    align-items: center;
    box-shadow: 0 -1px inset var(--b3-theme-background-light);
    font-size: 87.5%;

    &--show .block__icon {
      opacity: 1;
    }

    .block__icon svg {
      height: 1em;
      width: 1em;
    }

    .b3-text-field {
      transition: var(--b3-width-transition);
    }
  }

  &__title {
    outline: none;
    font-weight: bold;

    &:empty::after {
      color: var(--b3-theme-on-surface-light);
      content: attr(data-tip);
    }
  }

  &__counter {
    position: absolute;
    bottom: 0;
    height: 26px;
    padding: 0 5px;
    background-color: var(--av-background);
    font-size: 87.5%;
  }

  &__mask {
    position: fixed;
    top: 0;
    bottom: 0;
    right: 0;
    left: 0;
  }

  &__scroll {
    overflow: auto hidden;
  }

  &__body {
    float: left;
  }

  &__row {
    display: flex;
    border-bottom: 1px solid var(--b3-theme-surface-lighter);
    position: relative;
    font-size: 87.5%;

    &.dragover__bottom {
      border-bottom-color: var(--b3-theme-primary-lighter);
      z-index: 3;
    }

    &.dragover__top {
      z-index: 3;
      box-shadow: 0 -3px 0 var(--b3-theme-primary-lighter), inset 0 2px 0 var(--b3-theme-primary-lighter) !important;
    }

    &:hover [data-type="block-more"] {
      display: block;
    }

    &--select,
    &--hl {
      &:not(.av__row--header) .av__cell,
      &:not(.av__row--header) .av__firstcol {
        background-color: var(--b3-av-background-hl) !important;
      }

      .av__firstcol svg {
        opacity: 1;
      }
    }

    &--header {
      z-index: 3;

      & > .block__icons > .block__icon svg {
        height: 1em;
        width: 1em;
      }
    }

    &--header,
    &--footer {
      background-color: var(--av-background);
    }

    &--footer {
      display: flex;
      border-top: 1px solid var(--b3-theme-surface-lighter);
      color: var(--b3-theme-on-surface);
      position: relative;
      z-index: 2;

      &:hover .av__calc,
      &.av__row--show .av__calc {
        opacity: 1;
      }

      .av__colsticky {
        background-color: var(--av-background); // 保证盯住时无计算结果的列不被覆盖
      }

      .av__calc {
        display: flex;
        align-items: center;
        padding: 5px;
        border-right: 1px;
        flex-direction: row-reverse;
        box-sizing: border-box;
        opacity: 0;
        overflow: hidden;
        font-size: 75%;
        white-space: nowrap;
        cursor: pointer;

        &[data-dtype="lineNumber"] {
          cursor: inherit;
        }

        &:first-child {
          padding-left: 1.625em;
          box-sizing: initial;
        }

        &.av__calc--ashow {
          opacity: 1;
        }

        svg {
          margin-left: 5px;
          height: 1.625em;
          width: calc(1.625em - 10px);
        }

        span {
          font-size: 116%;
          color: var(--b3-theme-on-background);
          margin-left: 5px;
        }

        &:hover {
          background-color: var(--b3-av-hover);
        }
      }
    }

    &--util {
      display: flex;

      .b3-button {
        margin: 5px 0 5px 1.625em;
        color: var(--b3-theme-on-surface);
        background-color: transparent;
        font-size: 75%;

        &:hover,
        &:focus {
          background-color: var(--b3-av-hover);
          box-shadow: none;
        }
      }

      svg {
        height: 1.625em;
        width: calc(1.625em - 8px);

        &[data-type="set-page-size"] {
          margin: 0 0 0 4px;
          border-radius: var(--b3-border-radius);
          padding: 0 4px;

          &:hover {
            background-color: var(--b3-theme-background);
          }
        }
      }
    }
  }

  &__cell {
    box-sizing: border-box;
    position: relative;
    padding: 5px 8px;
    flex-shrink: 0;
    border-right: 1px solid var(--b3-theme-surface-lighter);
    overflow: hidden;
    cursor: pointer;
    //  display: flex; 不需要使用，否则 av__celltext 会占满单元格，导致链接列点击空白无法进行编辑

    [data-type="block-more"] {
      display: none;
      position: absolute;
      right: 5px;
      font-size: 85% !important;
      top: 7.5px;
    }

    .popover__block {
      color: var(--b3-protyle-inline-blockref-color);
    }

    &[data-wrap="true"] {
      white-space: pre-wrap;
    }

    &[data-wrap="false"] {
      white-space: nowrap;
    }

    &[data-block-id] > .block__icon[data-type="copy"] {
      display: none;
    }

    &.dragover__right {
      border-right-color: var(--b3-theme-primary-lighter);
    }

    &.dragover__left,
    &.dragover__right {
      z-index: 2;
    }

    &--select {
      background-color: var(--b3-menu-background);
      box-shadow: 2px 2px 0 var(--b3-theme-primary-lighter) inset, -2px -2px 0 var(--b3-theme-primary-lighter) inset;
      border-radius: var(--b3-border-radius);
    }

    &--active {
      background-color: var(--b3-menu-background);
    }

    &--header {
      padding: 5px 8px;
      display: flex;
      align-items: center;
      overflow: inherit; // 保证列宽和顺序调整的拖拽点样式
      border-right-color: transparent;

      &:hover {
        background-color: var(--b3-av-hover);
      }

      .av__celltext {
        white-space: nowrap;
        text-overflow: ellipsis;
      }

      img.av__cellheadericon {
        height: calc(1.625em - 10px);
      }

      .av__cellheadericon {
        height: 1.625em;
        width: calc(1.625em - 10px);
        color: var(--b3-theme-on-surface);
        margin: 0 5px 0 0;
        flex-shrink: 0;
        font-size: inherit;
        font-family: var(--b3-font-family-emoji);

        &--pin {
          margin: 0 0 0 5px;
        }
      }

    }

    .block__icon {
      position: absolute;
      right: 5px;
      top: 5px;
    }

    &:hover .block__icon {
      opacity: 1;
      background-color: var(--b3-theme-background-light) !important;
    }

    .b3-chip {
      margin: 1px 2px;
      padding: 2px 6px;
      line-height: calc(1.625em - 6px);
      font-size: inherit;
    }
  }

  &__drag-fill {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 9px;
    height: 9px;
    border: 2px solid var(--b3-theme-primary-lighter);
    border-radius: 50%;
    box-sizing: border-box;
    cursor: ns-resize;
  }

  &__celltext {
    overflow: hidden;

    &--url,
    &--ref {
      border-bottom: .5px solid var(--b3-border-color);
    }

    &--url.b3-chip {
      max-width: 120px;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      display: inline-block;
      vertical-align: top;
      border-bottom: 0;
    }

    & > .av__cellicon {
      margin: 0 5px;
      height: 10px;
      width: 10px;
    }
  }

  &__checkbox {
    color: var(--b3-theme-on-surface);
    height: 1.625em;
    width: calc(1.625em - 10px);
    box-sizing: border-box;
    padding: 5px 0;
    display: block;

    &:hover {
      color: var(--b3-theme-on-background);
    }
  }

  &__firstcol {
    svg {
      @extend .av__checkbox;
      opacity: 0;
      margin: 5px;
      cursor: pointer;
    }

    &:hover svg {
      opacity: 1;
    }
  }

  &__colsticky {
    position: sticky;
    left: 0;
    z-index: 2; // 需大于 av__widthdrag，否则横行滚动后，拖拽会悬浮于 stick 列上
    display: flex;

    &.av__firstcol,
    & > div:not(.av__cell--select):not(.av__cell--active):not(.av__calc--ashow) {
      background-color: var(--av-background);
    }
  }

  &__widthdrag {
    position: absolute;
    cursor: col-resize;
    width: 5px;
    height: 100%;
    right: -2.5px;
    transition: var(--b3-background-transition);
    z-index: 1;

    &:hover {
      background-color: var(--b3-theme-primary);
    }
  }

  &__panel {
    position: relative;

    .b3-menu {
      min-width: 200px;

      &__item .b3-chip {
        max-width: 90vw;
        margin: 3px 0;
        padding-top: 4px;
        padding-bottom: 4px;
        float: left;

        .icon {
          width: 12px;
          flex-shrink: 0;
          margin-right: 6px;
          margin-left: -5px;
        }
      }

      .b3-chips {
        padding: 0;

        input {
          outline: none;
          border: 0;
          background-color: var(--b3-menu-background);
          flex: 1;
          height: 30px;
          color: var(--b3-theme-on-background);
        }
      }

      .block__icon {
        line-height: 20px;
        padding: 0 4px;
        font-size: 12px;
        font-family: var(--b3-font-family-emoji);
        align-self: center;
        opacity: 1;
      }

      &__label {
        overflow: hidden;
      }

      &__icon.fn__grab {
        color: var(--b3-theme-on-surface-light);
      }

      &__item {
        transition: margin .2s cubic-bezier(0, 0, .2, 1) 0ms;

        &[disabled] {
          opacity: .38;
          cursor: not-allowed;
        }
      }

      &__item:hover .b3-menu__action {
        opacity: 1;
      }

      &__item[data-type="nobg"] {
        cursor: auto;
      }

      &__item:not([data-type="nobg"]):hover,
      &__item--current:not([data-type="nobg"]) {
        background-color: var(--b3-list-hover);
      }
    }
  }
}

.protyle-wysiwyg--select {
  .av__row--header,
  .av__row--footer,
  .av__row--footer .av__colsticky,
  .av__row--select .av__cell,
  .av__colsticky.av__firstcol,
  .av__colsticky > div,
  .av__cell--select,
  .av__cell--active,
  .av__counter {
    background-color: var(--b3-av-background-hl) !important;
  }
}

.protyle-wysiwyg--hl {
  .av__row--header,
  .av__row--footer,
  .av__row--footer .av__colsticky,
  .av__row--select .av__cell,
  .av__colsticky.av__firstcol,
  .av__colsticky > div,
  .av__cell--select,
  .av__cell--active,
  .av__counter {
    background-color: var(--b3-av-background-hl) !important;
    transition: var(--b3-background-transition);
  }
}

.dragover__top,
.dragover__bottom {
  .av__colsticky {
    &.av__firstcol,
    & > div:not(.av__cell--select):not(.av__cell--active):not(.av__calc--ashow) {
      background-color: transparent;
    }
  }
}

img.av__cellassetimg {
  max-height: calc(1.625em - 2px);
  border-radius: var(--b3-border-radius);
  margin: 1px 2px;
  max-width: none;
  vertical-align: top;
  font-size: inherit;
}

html[data-theme-mode="dark"] .av__panel .b3-menu__item[draggable="true"] {
  mix-blend-mode: lighten;
}

html[data-theme-mode="light"] .av__panel .b3-menu__item[draggable="true"] {
  mix-blend-mode: darken;
}
